package com.ruoyi.web.controller.business;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.AdvertisementMoneyConfig;
import com.ruoyi.system.service.IAdvertisementMoneyConfigService;
import com.ruoyi.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2023-05-17
 */
@RestController
@RequestMapping("/system/moneyConfig")
public class AdvertisementMoneyConfigController extends BaseController
{
    @Autowired
    private IAdvertisementMoneyConfigService advertisementMoneyConfigService;

    @Autowired
    private ISysDeptService deptService;

    /**
     * 查询【请填写功能名称】列表
     */
//    @PreAuthorize("@ss.hasPermi('system:moneyConfig:list')")
    @GetMapping("/list")
    @Anonymous
    public TableDataInfo list(AdvertisementMoneyConfig advertisementMoneyConfig)
    {


        startPage();
        List<AdvertisementMoneyConfig> list = advertisementMoneyConfigService.selectAdvertisementMoneyConfigList(advertisementMoneyConfig);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:moneyConfig:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AdvertisementMoneyConfig advertisementMoneyConfig)
    {
        List<AdvertisementMoneyConfig> list = advertisementMoneyConfigService.selectAdvertisementMoneyConfigList(advertisementMoneyConfig);
        ExcelUtil<AdvertisementMoneyConfig> util = new ExcelUtil<AdvertisementMoneyConfig>(AdvertisementMoneyConfig.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:moneyConfig:query')")
    @GetMapping(value = "/{moneyId}")
    public AjaxResult getInfo(@PathVariable("moneyId") Long moneyId)
    {
        return success(advertisementMoneyConfigService.selectAdvertisementMoneyConfigByMoneyId(moneyId));
    }

    /**
     * 新增【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('system:moneyConfig:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @Anonymous
    @PostMapping
    public AjaxResult add(@RequestBody AdvertisementMoneyConfig advertisementMoneyConfig)
    {

//        SysDept dept = new SysDept();
//        List<SysDept> depts = deptService.selectDeptList(dept);
//
//        for (int i = 0, j = depts.size(); i < j; i++) {
//            AdvertisementMoneyConfig advertisementMoneyConfig1 = new AdvertisementMoneyConfig();
////            advertisementMoneyConfig1.setMoneyId(Long.valueOf(1));
//            advertisementMoneyConfig1.setCityId(depts.get(i).getDeptName());
//            advertisementMoneyConfig1.setCategoryId(advertisementMoneyConfig.getCityId());
//            advertisementMoneyConfig1.setCustomerDays("10");
//            advertisementMoneyConfig1.setLargePrice("10");
//            advertisementMoneyConfig1.setRecommendPrice("10");
//            advertisementMoneyConfigService.insertAdvertisementMoneyConfig(advertisementMoneyConfig1);
//        }

        return toAjax(advertisementMoneyConfigService.insertAdvertisementMoneyConfig(advertisementMoneyConfig));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:moneyConfig:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdvertisementMoneyConfig advertisementMoneyConfig)
    {
        return toAjax(advertisementMoneyConfigService.updateAdvertisementMoneyConfig(advertisementMoneyConfig));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:moneyConfig:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{moneyIds}")
    public AjaxResult remove(@PathVariable Long[] moneyIds)
    {
        return toAjax(advertisementMoneyConfigService.deleteAdvertisementMoneyConfigByMoneyIds(moneyIds));
    }
}
